<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>notify-rule-eventtype</title>
	 <%@ include file="../include/common.jsp"%>
	 <%@ include file="../include/tree.jsp"%>
    <%@ include file="../include/form.jsp"%>
    <%@ include file="../include/jbox.jsp"%>
	<style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;width:220px;height:360px;overflow-y:scroll;overflow-x:auto;}
	</style>
	<link rel="stylesheet" media="all" type="text/css" href="${pageContext.request.contextPath}/style/default/tree/demo.css" />
<script type="text/javascript">
		
	  function add(){
		  if($("#eventTypeId").val() == ''){
			  window.setTimeout(function () { $.jBox.tip('请勾选事件类别', 'success'); }, 100);
			  return false;
		  }
		var pWin = getTopWin(window).currentWin["add-eventtype-rule"];
		pWin.setEventTypeId($("#eventTypeId").val(),$("#eventTypeName").val());
		getTopWin(window).closejBox("add-eventtype-rule");
	  }
	$(function(){
		showEventTypeTree();
		$.formValidator.initConfig({formid:"myform"
	          ,onerror:function(msg){}
	          ,onsuccess:function(){
	        	  		add();
	          			return false;
	          }
	    });
	})
	function closewin(){
	  getTopWin(window).closejBox("add-eventtype-rule");
  }
 
	function showEventTypeTree(){
		$.ajax({ 
			  type:"post", 
			  url:"${pageContext.request.contextPath}/notify/notify-rule!eventTypeViewTree.action?eventType="+'${eventType}'+"&notifyRuleId="+'${notifyRuleId}', 
			  data:"", 
			  datatype:"json",
			  success:function(data) { 
					var zNodes=eval(data);
					$.fn.zTree.init($("#treeDemo"), eventTypeSetting, zNodes);
			  } 
	     	})
}
var eventTypeSetting = {
		check: {
			enable: true,
			chkboxType: {"Y" : "", "N" : ""}
		},
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onCheck: onCheck
		}
	};
function onCheck(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	nodes = zTree.getCheckedNodes(true),
	v = "";
	m = "";
	for (var i=0, l=nodes.length; i<l; i++) {
		//根节点是虚的 不显示
		if(nodes[i].id != -1){
			v += nodes[i].name + ",";
		}
		m += nodes[i].id + ",";
	}
	if (v.length > 0 ) v = v.substring(0, v.length-1);
	if (m.length > 0 ) m = m.substring(0, m.length-1);
	$("#eventTypeId").val(m);
	$("#eventTypeName").val(v);
}
	</script>
  </head>
  
  <body class="padding-8">
  		<form action="" id="myform" name="myform" method="post">
    		<div align="left" style="margin-bottom: 5px">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    		<input id="eventTypeId" name="eventTypeId" type="hidden" value="${eventType}">
    		<input id="eventTypeName" name="eventTypeName" type="hidden" value="${eventTypeName}">
    	</form>
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:300px; height: 260px;"></ul>
  </body>
</html>
